// 文件名：week1\problem\lc187_欧琳琳.cpp
// 提交链接：https://leetcode.cn/problems/repeated-dna-sequences/submissions/559547565?envType=problem-list-v2&envId=sliding-window&status=SOLVED
// 187. 位运算，哈希表，哈希函数，滚动哈希，字符串，滑动窗口
// 完成日期：2024/08/29
// c++,创建了两个哈希表，time1用于存储遇到的所有子字符串，timeup1用于存储重复出现的子字符串。然后用滑动窗口解决长度为10的重复子串

class Solution {
public:
    vector<string> findRepeatedDnaSequences(string s) {
        int n= s.length();
        unordered_set<string>time1;
        unordered_set<string>timeup1;
        for(int i=0;i<=n-10;i++)
        {
            string substring=s.substr(i,10);
            if(time1.count(substring))
            {
                timeup1.insert(substring);
            }
            else
            {
                time1.insert(substring);
            }
        }
        vector<string>res;
        res.assign(timeup1.begin(),timeup1.end());
        return res;
    }
};